﻿<!--#include file="/parts/head.html" -->
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  <h1 id="title" data-navbaractive="navallminers" class="h2">Miners</h1>
</div>
<table id="miners" class="table"
  data-toggle="table"
  data-url="/miners"
  data-response-handler="formatMiners"
  data-filter-control="true"
  data-filter-show-clear="true"
  data-sort-order="desc"
  data-sort-name="Profit"
  data-cache="false"
  data-show-columns="true"
  data-show-toggle="true"
  data-show-refresh="true"
  data-icons-prefix="fa"
  data-icons="icons"
  data-detail-view="true"
  data-detail-formatter="detailFormatter"
>
  <thead>
      <tr>
          <th data-field="Name" data-sortable="true" data-filter-control="select" data-filter-strict-search="true">Name</th>
          <th data-field="tDevices" data-sortable="true" data-filter-control="select" data-filter-strict-search="true">Devices</th>
          <th data-field="Profit" data-align="right" data-sortable="true" data-formatter="formatBTC">Profit</th>
          <th data-field="tPowerDraw" data-sortable="true">Power</th>
          <th data-field="tPrimaryAlgorithm" data-sortable="true" data-filter-control="select" data-filter-strict-search="true">Algorithm</th>
          <th data-field="tPrimaryHashRate" data-sortable="true" data-formatter="formatHashRateValue">Primary Speed</th>
          <th data-field="tSecondaryAlgorithm" data-sortable="true" data-filter-control="select" data-filter-strict-search="true">2nd Algo</th>
          <th data-field="tSecondaryHashRate" data-sortable="true" data-formatter="formatHashRateValue">2nd Speed</th>
      </tr>
  </thead>
</table>

<!-- End of page scripts -->
<script type="text/javascript">
    $(function () {
        function refreshTable() {            
            if (!$("table#miners tr.detail-view").length) $("table#miners").bootstrapTable("refresh", { silent: true });
            window.setTimeout(refreshTable, 10000);
        }
        window.setTimeout(refreshTable, 10000);
    });

    function formatMiners(data) {
        // This function can alter the returned data before building the table, formatting it in a way
        // that is easier to display and manipulate in a table
        $.each(data, function (index, item) {
            // Format the device(s)
            item.tDevices = item.DeviceModel.toString();
            item.Name = item.Name.split(/\-/)[0];
            if (item.ManualUri && item.ManualUri.toString() != '') {
                item.Name = '<a href="'+item.ManualUri.toString()+'" target="_blank" title="Official miner page">'+item.Name+'</a>';
            }

            // Format the algorithms and hashrates
            var algorithms = Object.keys(item.HashRates);
            item.tPrimaryAlgorithm = algorithms[0];
            item.tSecondaryAlgorithm = algorithms[1];
            item.tPrimaryHashRate = item.HashRates[algorithms[0]];
            item.tSecondaryHashRate = item.HashRates[algorithms[1]];

            item.tPowerDraw = Math.round(parseFloat(item.PowerDraw)) + ' W';
        });
        return data;
    }
</script>
<!--#include file="/parts/foot.html" -->